﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Forms;

public class DownloadHelper
{
    public string GetHtmlFromUrl(string url)
    {
        try
        {
            string html = "";
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.UserAgent = "Mozilla/5.0";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // get the response stream.
            //Stream responseStream = response.GetResponseStream();
            // use a stream reader that understands UTF8
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            html = reader.ReadToEnd();
            // close the reader
            reader.Close();
            response.Close();
            return html;//return conten html
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return "";
        }
    }

    public Stream GetStreamImageFromUrl(string url)
    {
        try
        {
            Stream stream;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.UserAgent = "Mozilla/5.0";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
           
            stream = response.GetResponseStream();
            return stream;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return null;
        }
    }

    public DownloadHelper()
    {

    }

}

